package com.dfwl.packageio.core.db;

import com.dfwl.packageio.core.base.EntityBase;
import com.dfwl.packageio.core.bean.BarCodeInfo;
import com.lidroid.xutils.db.table.DbModel;
import com.lidroid.xutils.exception.DbException;
import com.lidroid.xutils.util.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @auth &{zhujiule}
 * @date 2018/8/13
 * @copyright 杭州物恋网科技有限公司
 **/
public class BarCodeDao  extends AbsDbOperation{
   @Override
   public String getDbName() {
      return "PACKINGIO";
   }

   @Override
   public <T extends List<? extends EntityBase>> T selectDataFromDb(String sql) {
      List<DbModel> dbModels = null;
      ArrayList<BarCodeInfo> mData = new ArrayList<>();
      try {
         dbModels = getDbManager().getContentDb().findDbModelAll(sql);
         for (DbModel mDbModle : dbModels) {
            BarCodeInfo mBarCode = new BarCodeInfo();
            mBarCode.setId(mDbModle.getInt("id"));
            mBarCode.setExpressCode(mDbModle.getString("EXPRESS_CODE"));
            mBarCode.setEnterDate(mDbModle.getDate("ENTER_DATE"));
            mBarCode.setBoxNo(mDbModle.getString("BOX_NO"));
            mBarCode.setUpload(mDbModle.getInt("UPLOAD"));
            mData.add(mBarCode);
         }
      } catch (DbException e) {

         LogUtils.i("esdf",e);

      } finally {
         if (dbModels != null) {
            dbModels.clear();
         }
      }
      return (T) mData;
   }

   public void delBaseExpressCode(String wxpressCode){
      String sql = "delete from PACKINGIO where EXPRESS_CODE ='"+wxpressCode+"'";
      deleteDataFromDb(sql);
   }

   public void delBaseBoxCode(String boxNo){
      String sql = "delete from PACKINGIO where BOX_NO ='"+boxNo+"'";
      deleteDataFromDb(sql);
   }
}
